package art_of_java_concurrent_programming.executor;

import java.util.concurrent.*;

/**
 * @author lixiangke
 * @date 2018/3/6
 */
public class ScheduledThreadPoolExecutorTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor)
                Executors.newScheduledThreadPool(2);
        executor.scheduleAtFixedRate(new ScheduledTask(),
                1, 2, TimeUnit.SECONDS);
        Future<String> future = executor.submit(new CallableTask());
        System.out.println(future.get());
    }

    private static class ScheduledTask implements Runnable {

        @Override
        public void run() {
            System.out.println(System.currentTimeMillis());
        }
    }

    private static class CallableTask implements Callable<String> {

        @Override
        public String call() throws Exception {
            return "hello, " + System.currentTimeMillis();
        }
    }
}
